package com.yunzheng.studyLeaveSystem.modules.admin.search.week.dao.Impl;

import com.yunzheng.studyLeaveSystem.modules.admin.search.week.dao.SearchDao;
import com.yunzheng.studyLeaveSystem.modules.admin.search.week.entity.SearchEntity;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SearchDaoImpl implements SearchDao {
    public List<SearchEntity> queryInformation(String name) throws Exception {
        Connection connection = DBUtils.getCon();
        List<SearchEntity> InformationList = new ArrayList<>();
        String sql = "select leave_date,leave_class,adjust_date,adjust_class,reason from adjust where leaver_name =? ";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            SearchEntity searchEntity = new SearchEntity();
            searchEntity.setLeave_date(resultSet.getString("leave_date"));
            searchEntity.setLeave_class(resultSet.getString("leave_class"));
            searchEntity.setAdjust_date(resultSet.getString("adjust_date"));
            searchEntity.setAdjust_class(resultSet.getString("adjust_class"));
            searchEntity.setReason(resultSet.getString("reason"));
            String adjust_class;
            InformationList.add(searchEntity);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return InformationList;
    }
}
